package ca.jsbr.as2js_lib.display.canvas.bitmap.imageFilter 
{
	import ca.jsbr.as2js_lib.display.canvas.bitmap.BitmapData;
	import js.ImageData;
	/**
	 * ...
	 * @author jsbr [jsricard@lvlstudio.com]
	 */
	public class AdjustColor implements IFilter 
	{
		private var _saturation:Number;
		private var _bitmapData:BitmapData;
		private var 
		
		public function AdjustColor() 
		{
			
		}
		
		
		public function get saturation():Number 
		{
			return _saturation;
		}
		
		public function set saturation(value:Number):void 
		{
			_saturation = value;
			bitmapData.modified = true;
		}
		
		/* INTERFACE ca.jsbr.as2js_lib.display.canvas.bitmap.imageFilter.IFilter */
		
		public function render(bitmapData:BitmapData):ImageData 
		{
			_bitmapData = bitmapData;
			var data:Array = bitmapData.data;
			for (var i:int = 0; i < len; i+=4)
			{
				var avg:Number = (data[i] + data[i + 1] + data[i + 2]) / 3;
				var r = (data[i] - avg) * _saturation;
				var g = (data[i] - avg) * _saturation;
				var b = (data[i] - avg) * _saturation;
				data[i] = data[i] -r;
				data[i + 1] = data[i + 1] -g;
				data[i + 2] = data[i + 2] -b;
			}
		}
		
		
	}

}